﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;

namespace MiddlewarePlugins
{
    /// <summary>
    /// 中间接测试
    /// https://learn.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?view=aspnetcore-6.0
    /// </summary>
    public static class MiddlewareTestOne
    {

        public static void MiddlewareTest(this WebApplication app)
        {
            //app.Use(async (context, next) => {
            //    await next.Invoke();
            //});

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("middlewaretest1");
            //});

            #region 这部分是官方的一个示例，访问特定路径会调用中间件
            //app.Map("/map1", HandleMapTest1);

            //app.Map("/map2", HandleMapTest2);

            //app.Run(async context =>
            //{
            //    await context.Response.WriteAsync("Hello from non-Map delegate. <p>");
            //});

            //app.Run();

            //static void HandleMapTest1(IApplicationBuilder app)
            //{
            //    app.Run(async context =>
            //    {
            //        await context.Response.WriteAsync("Map Test 1");
            //    });
            //}

            //static void HandleMapTest2(IApplicationBuilder app)
            //{
            //    app.Run(async context =>
            //    {
            //        await context.Response.WriteAsync("Map Test 2");
            //    });
            //}
            #endregion
        }
    }
}
